<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Accordion</title>
    <style>
        .accordion {
            width: 200px;
            overflow: hidden;
            border: 1px solid #ccc;
            transition: height 0.3s;
        }

        .accordion-item {
            padding: 5px;
            background-color: #f0f0f0;
            cursor: pointer;
        }

        .accordion-content {
            padding: 5px;
            background-color: #ccc;
            height: 30%; /* 初始时只显示30% */
            overflow: hidden;
            transition: height 0.3s;
        }

        .accordion-item.active .accordion-content {
            height: 100%; /* 鼠标悬停时展开显示全部 */
        }
    </style>
</head>

<body>

    <div class="accordion">
        <div class="accordion-item">
            <div class="accordion-content">
                <div>标题1</div>
                <div>内容1</div>
            </div>
        </div>
        <div class="accordion-item">
            <div class="accordion-content">
                <div>标题2</div>
                <div>内容2</div>
            </div>
        </div>
        <div class="accordion-item">
            <div class="accordion-content">
                <div>标题3</div>
                <div>内容3</div>
            </div>
        </div>
    </div>

    <script>
        const accordionItems = document.querySelectorAll('.accordion-item');

        accordionItems.forEach(item => {
            item.addEventListener('mouseenter', () => {
                accordionItems.forEach(otherItem => {
                    otherItem.classList.remove('active');
                });

                item.classList.add('active');
            });

            item.addEventListener('mouseleave', () => {
                item.classList.remove('active');
            });
        });
    </script>

</body>

</html>
